class Stack {
  constructor() {
    this.data = []
    this.count = 0
  }

  // 入栈
  push(item) {
    this.data[this.count] = item
    this.count++
  }

  // 出栈
  pop() {
    if (this.isEmpty()) {
      return
    }
    const temp = this.data[this.count - 1]
    delete this.data[--this.count]
    return temp
  }

  // 获取栈顶
  top() {
    if (this.isEmpty()) {
      return
    }
    return this.data[this.count - 1]
  }

  // 获取长度
  size() {
    return this.count
  }

  clear() {
    this.data = []
    this.count = 0
  }

  isEmpty() {
    return this.count === 0
  }
}

const s = new Stack()
